package org.nw.web.sys;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nw.constants.Constants;
import org.nw.service.IToftService;
import org.nw.service.sys.FunService;
import org.nw.service.sys.ImportColumnService;
import org.nw.vo.TreeVO;
import org.nw.vo.sys.ImportColumnVO;
import org.nw.web.AbsToftController;
import org.nw.web.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 导入字段定义
 * 
 * @author xuqc
 * @date 2012-6-10 下午03:38:27
 */
@Controller
@RequestMapping(value = "/ic")
public class ImportColumnController extends AbsToftController {

	@Autowired
	private ImportColumnService importColumnService;

	@Autowired
	private FunService funService;

	@Override
	public IToftService getService() {
		return importColumnService;
	}

	/**
	 * 查询当前用户授权的菜单
	 * 
	 * @param request
	 * @param response
	 * @param parentFunCode
	 *            父级节点编码
	 * @return
	 */
	@RequestMapping(value = "/getFunTree.json")
	@ResponseBody
	public List<TreeVO> getFunTree(HttpServletRequest request, HttpServletResponse response) {
		// List<TreeVO> funTree =
		// funService.getFunTree(WebUtils.getLoginInfo().getPk_corp(),
		// WebUtils.getLoginInfo()
		// .getPk_user(), Constants.SYSTEM_CODE);
		TreeVO[] treeVOs = funService.getFunTree(WebUtils.getLoginInfo().getPk_corp(), WebUtils.getLoginInfo()
				.getPk_user(), Constants.SYSTEM_CODE, true);
		List<TreeVO> funTree = null;
		if(treeVOs == null) {
			// 返回一个null对象，js会报错
			funTree = new ArrayList<TreeVO>();
		}
		funTree = Arrays.asList(treeVOs);
		return funTree;
	}

	@Override
	public String getTreePkField() {
		return ImportColumnVO.PK_FUN;
	}
}
